package acwing.lq.递归and递推;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

/**
 * @description:
 * @author: qian
 * @createDate: 2021/11/12
 */
public class 带分数 {

    static int n;
    static int ans;
    static int N = 10;
    static boolean[] st = new boolean[N]; // 判重数组
    static int[] arr = new int[N];
    static BufferedWriter wr;

    public static void main(String[] args) throws Exception {

        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
        wr = new BufferedWriter(new OutputStreamWriter(System.out));
        n = Integer.parseInt(rd.readLine().trim());
        dfs(1);
        wr.write(ans + "");
        wr.flush();
    }

    private static void dfs(int k) {

        if (k > 9) {
            for (int i = 1; i <= 7; i++) {
                for (int j = i + 1; j <= 8; j++) {
                    int a = cal(1,i);
                    int b = cal(i + 1,j);
                    int c = cal(j + 1,9);
                    if (c * n == c * a + b)
                        ans++;
                }
            }
            return;
        }

        for (int i = 1; i <= 9; i++) {
            if (!st[i]) {
                st[i] = true;
                arr[k] = i;
                dfs(k + 1);
                st[i] = false;
            }
        }
    }

    // 计算
    private static int cal(int a, int b) {
        int res = 0;
        for (int i = a; i <= b; i++) {
            res = res * 10 + arr[i];
        }
        return res;
    }
}
